package com.wanxi.servlet.lawyer;

import com.alibaba.fastjson.JSONObject;
import com.wanxi.dto.ResultDto;
import com.wanxi.model.LawyerModel;
import com.wanxi.service.Impl.LawyerServiceImpl;
import com.wanxi.service.LawyerService;
import com.wanxi.util.Tool;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @author Li
 * @Date 2023/5/4 21:16
 */
@WebServlet("/back/FindLawyerById")
public class FindLawyerByIdServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.乱码处理
        req.setCharacterEncoding("UTF-8");
        resp.setCharacterEncoding("UTF-8");
//        2.接收前端数据
        String id = req.getParameter("id");
//        3.封装model
        LawyerModel lawyerModel = LawyerModel.builder()
                .id(Tool.nullToInt(id))
                .build();
        //4.调用service层
        LawyerService lawyerService = new LawyerServiceImpl();
        ResultDto resultDto = lawyerService.findById(lawyerModel);
        //5.返回给前端值
        resp.getWriter().println(JSONObject.toJSONString(resultDto));
    }
}
